
//
//  GQHQutationModel.m
//  Xanthium
//
//  Created by GuanQinghao on 12/04/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHQutationModel.h"


@implementation GQHQutationModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"qh_qutationID" : @"id",
             @"qh_amountValue" : @"offer",
             @"qh_amountString" : @"offerString",
             @"qh_quoteState" : @"state",
             @"qh_quoteTime" : @"offerTime",
             @"qh_note" : @"note",
             @"qh_freightID" : @"sourcesId",
             @"qh_departureID" : @"origin",
             @"qh_departure" : @"origin",
             @"qh_destinationID" : @"destination",
             @"qh_destination" : @"destination",
             @"qh_mileage" : @"mileage",
             @"qh_freightName" : @"commodityName",
             @"qh_freightWeight" : @"demandVehicle",
             @"qh_freightType" : @"commodityName",
             @"qh_freightTypeCode" : @"commodityName",
             @"qh_modelWanted" : @"demandModels",
             @"qh_lengthWanted" : @"demandVehicleLength",
             @"qh_loader" : @"releasePeople",
             @"qh_loaderMobile" : @"releasePeoplePhone",
             @"qh_loadingTime" : @"loadingTime",
             @"qh_contractID" : @"buWaybillAgreementId",
             @"qh_quoterID" : @"userId",
             @"qh_quoterName" : @"empName",
             @"qh_quoterAvatar" : @"headPicture",
             @"qh_quoterMobile" : @"drivePhone",
             @"qh_quoterScore" : @"score",
             @"qh_modelCode" : @"licenseplatetypecode",
             @"qh_model" : @"vehicleclassificationcode",
             @"qh_licensePlateNumber" : @"licenseplatetypecode",
             @"qh_normalLength" : @"carLength",
             @"qh_normalLoading" : @"carLoad"
             };
}

///  获取报价列表
+ (void)qh_fetchQutationsWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHQutationModel *> *qutations))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buQuotationRecord/1/findAll"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *qutationArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHQutationModel *qutationModel = [GQHQutationModel yy_modelWithDictionary:object];
                if (qutationModel) {
                    
                    [qutationArray addObject:qutationModel];
                }
            }
            success(YES,code,message,qutationArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

@end
